package kr.hkit.powerjava.chapter14.work;

import java.awt.CardLayout;
import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.util.Scanner;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;

import kr.hkit.powerjava.chapter14.work.dto.Employee;
import kr.hkit.powerjava.chapter14.work.service.AbsService;
import kr.hkit.powerjava.chapter14.work.service.EmployeeService;

public class TestMain extends JFrame implements ActionListener {

	Scanner sc = new Scanner(System.in);
	Connection connection = ConnectionFactory.getConnection();

	private JPanel contentPane;
	private JPanel mainMenu;
	private JPanel empMenu;
	private JPanel deptMenu;
	private JPanel prnPanel;
	private JButton btnEmp;
	private JButton btnDept;
	private JButton btnEnd;
	private JButton btnDelete;
	private JButton btnSearch;
	private JButton btnUpdate;
	private JButton btnPrn;
	private JButton btnEmpEnd;
	private JButton btnInsert;
	private JPanel panel;
	private JLabel lblNewLabel;
	private JLabel label;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TestMain frame = new TestMain();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public TestMain() {
		initialize();
	}
	private void initialize() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new CardLayout(0, 0));
		
		mainMenu = new JPanel();
		contentPane.add(mainMenu, "name_9525703291559");
		
		btnEmp = new JButton("사원관리");
		btnEmp.addActionListener(this);
		mainMenu.setLayout(new GridLayout(0, 1, 0, 0));
		
		label = new JLabel("메인메뉴");
		mainMenu.add(label);
		label.setHorizontalAlignment(SwingConstants.CENTER);
		mainMenu.add(btnEmp);
		
		btnDept = new JButton("부서관리");
		btnDept.addActionListener(this);
		mainMenu.add(btnDept);
		
		btnEnd = new JButton("종료");
		btnEnd.addActionListener(this);
		mainMenu.add(btnEnd);
		
		empMenu = new JPanel();
		contentPane.add(empMenu, "name_9525722534361");
		empMenu.setLayout(new BoxLayout(empMenu, BoxLayout.Y_AXIS));
		
		panel = new JPanel();
		empMenu.add(panel);
		panel.setLayout(new GridLayout(0, 1, 0, 0));
		
		btnInsert = new JButton("추가");
		btnInsert.addActionListener(this);
		
		lblNewLabel = new JLabel("사원관리");
		panel.add(lblNewLabel);
		lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
		panel.add(btnInsert);
		
		btnDelete = new JButton("삭제");
		btnDelete.addActionListener(this);
		panel.add(btnDelete);
		
		btnSearch = new JButton("검색");
		btnSearch.addActionListener(this);
		panel.add(btnSearch);
		
		btnUpdate = new JButton("수정");
		btnUpdate.addActionListener(this);
		panel.add(btnUpdate);
		
		btnPrn = new JButton("출력");
		btnPrn.addActionListener(this);
		panel.add(btnPrn);
		
		btnEmpEnd = new JButton("메인으로");
		btnEmpEnd.addActionListener(this);
		panel.add(btnEmpEnd);
		
		deptMenu = new JPanel();
		contentPane.add(deptMenu, "name_9525738663537");
		
		prnPanel = new JPanel();
		contentPane.add(prnPanel, "name_9525754766843");
		
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getActionCommand().equals("사원관리")) {
			mainMenu.setVisible(false);
			empMenu.setVisible(true);
			
			AbsService<Employee> empSvc = new EmployeeService(sc,
					connection);
			if (e.getActionCommand().equals("추가")){
				empSvc.prnMenu(1);
				prnPanel.setVisible(true);
				empMenu.setVisible(false);
			} /*else if (e.getActionCommand().equals("삭제")){
				
			} else if (e.getActionCommand().equals("검색")){
				
			} else if (e.getActionCommand().equals("수정")){
				
			} else if (e.getActionCommand().equals("출력")){
				
			}*/ else if (e.getActionCommand().equals("메인으로")){
				mainMenu.setVisible(true);
				empMenu.setVisible(false);
			}
		} else if (e.getActionCommand().equals("부서관리")) {
			mainMenu.setVisible(false);
			deptMenu.setVisible(true);
		} else if (e.getActionCommand().equals("종료")){
			System.exit(0);
			
		}
	}
}
